package util;

import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.util.Objects;

/**
 * @fileName: UsbChecker
 * @author: Han
 * @date: 2018/5/28 13:46
 * @dscription:
 */
public class UsbChecker {

    public static void main(String... args) {
        new UsbChecker().check();
    }

    private void check() {
        int i = 0;
        BufferedOutputStream bufferedOutputStream = null;
        try {
            byte[] bytes = new byte[1024];
            bufferedOutputStream = new BufferedOutputStream(new FileOutputStream("G://" + System
                    .currentTimeMillis() + ".txt"));
            for (;i < Integer.MAX_VALUE;i ++) {
                if (i % (1024 * 500) == 0 && i != 0) {
                    Objects.requireNonNull(bufferedOutputStream).close();
                    bufferedOutputStream = new BufferedOutputStream(new FileOutputStream("G://" + System
                            .currentTimeMillis() + ".txt"));
                }
                bufferedOutputStream.write(bytes);
                if (i % 1024 == 0 && i != 0) {
                    System.out.println("目前:" + i / 1024 + "M");
                }
            }
        } catch (Exception e) {
            System.out.println("U盘容量大致为:" + i + "KB");
            e.printStackTrace();
        } finally {
            try {
                Objects.requireNonNull(bufferedOutputStream).close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
